const {getHotSearch} = require("../../api/index")

Page({
    data: {
      value: '',
      hotSearch:[]
    },
    // 内容改变
    onChange(e) {
      this.setData({
        value: e.detail,
      });
    },
    // 回车实现搜索
    onSearch() {
      console.log('搜索' + this.data.value);
      this.goTogoods()
    },
    // 点击按钮触发
    onSearchClick() {
      console.log('搜索' + this.data.value);
      this.goTogoods()
    },
    onLoad(){
        getHotSearch().then(res => {
            console.log(res.data.data.result);
            this.setData({
                hotSearch:res.data.data.result
            })
        })
    },
    clickGetKeywords(e){
        console.log(e.currentTarget.dataset.hotkey);
        this.setData({
            value:e.currentTarget.dataset.hotkey
        });
        this.goTogoods()
    },
    goTogoods(){
        if(this.data.value) {
            wx.navigateTo({
                url: '/pages/goods/goods?search=' + this.data.value,
            })
        }
    }
  });
  